package com.example.uiview_025;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TimePicker;
import android.widget.Toast;

public class DatePickerActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_date_picker);
		Calendar calendar = Calendar.getInstance();
		DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
		
		datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONDAY), calendar.get(Calendar.DAY_OF_MONTH),new OnDateChangedListener() {
			
			@Override
			public void onDateChanged(DatePicker arg0, int year, int month, int dayOfMonth) {
				Toast.makeText(DatePickerActivity.this, year+"/"+month+"/"+dayOfMonth, 0).show();
				
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.data_picker, menu);
		return true;
	}
	
	
	public void showDate(View view){
		DatePickerDialog datePickerDialog = new DatePickerDialog(this, new OnDateSetListener() {
			@Override
			public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
				Toast.makeText(DatePickerActivity.this, arg1+"/"+arg2+"/"+arg3, 0).show();
				
			}
		}, 2013, 5, 12);
		datePickerDialog.show();
	}
	
	public void showTime(View view){
		new TimePickerDialog(this, new OnTimeSetListener() {
			
			@Override
			public void onTimeSet(TimePicker arg0, int arg1, int arg2) {
				Toast.makeText(DatePickerActivity.this, arg1+"/"+arg2, 0).show();
				
			}
		}, 12, 12, true).show();
		
	}

}
